****************co2 and financial depth************
//set the data path
cd d:/
use final_data,clear  //load the data

**************
bysort province: egen energy_d=mean(fossild1)
gen fdepth2= fdepth^2
tabstat energy_d, stat(p50)

gen energy_dum=0
replace energy_dum=1 if energy_d>0.721395


//set the panel data
egen id=group(province)
xtset id year
gen fdepth3=fdepth^3

*****************************data description**********************
sum per_co2 SW fdepth l_per_gdp tech struct_s gdp_a cpi l_population l_fdi internet_use  env_regul   stru_2 fossild1   l_trade

des per_co2 SW fdepth l_per_gdp tech struct_s gdp_a cpi l_population l_fdi internet_use  env_regul   stru_2 fossild1  l_trade


//statisitcal anlysis
 xtunitroot fisher per_co2, dfuller lags(3) drift
 xtunitroot fisher fdepth, dfuller lags(3) drift
collin  fdepth l_per_gdp   tech    gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 l_trade
des fdepth l_per_gdp   tech    gdp_a cpi l_population l_fdi internet_use  env_regul l_trade


//besic result
reg per_co2 fdepth   gdp_a cpi l_population  internet_use  env_regul  tech stru_2  l_fdi  
est store reg1
xtgls per_co2  fdepth   gdp_a cpi l_population  internet_use  env_regul  tech stru_2 l_fdi i.year, panels(hetero)
est store reg2
xtreg per_co2  fdepth   gdp_a cpi l_population  internet_use  env_regul  tech stru_2 l_fdi ,fe
est store reg3
xtreg per_co2  fdepth   gdp_a cpi l_population  internet_use  env_regul  tech stru_2 l_fdi,re
est store reg4
xtreg per_co2  fdepth  fdepth2  gdp_a cpi l_population  internet_use  env_regul  tech stru_2 l_fdi ,fe
est store reg5
esttab reg1 reg2 reg3 reg4 reg5 , cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth  fdepth2   gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2  _cons) ///
legend label varwidth(60) varlabels(_cons Constant) mtitles("ols" "FGLS" "FE" "RE" "FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  

hausman reg3 reg4,sigmamore


lowess per_co2 fdepth



xtreg per_co2  c.fdepth##c.fdepth   gdp_a cpi l_population  internet_use  env_regul  tech stru_2 l_fdi if energy_dum==0, fe
margins, at(fdepth=(1(0.5)10)) atmeans
marginsplot,ylab(-5(1)10)

xtreg per_co2  c.fdepth##c.fdepth##c.fdepth  gdp_a cpi l_population  internet_use  env_regul  tech stru_2 l_fdi energy_dum if energy_dum==1, fe
margins, at(fdepth=(1(0.5)10)) atmeans
marginsplot




//Moderating Effect

xtreg per_co2  fdepth l_per_gdp   tech struct_s   gdp_a cpi l_population l_fdi internet_use  env_regul stru_2  l_trade,fe
est store reg1

xtreg l_per_gdp  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul stru_2  l_trade,fe
est store reg3
xtreg tech  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul stru_2  l_trade,fe
est store reg4
xtreg struct_s  fdepth      gdp_a cpi l_population l_fdi internet_use  env_regul stru_2  l_trade,fe
est store reg5
esttab   reg3 reg4 reg5 reg1, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth l_per_gdp  gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 l_trade tech struct_s _cons) ///
legend label varwidth(60) varlabels(_cons Constant) mtitles("per_co2"  "l_per_gdp" "tech" "struc_third") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  


*********************************************
hist fossild1,bin(40)



//Economical scale effect
tabstat fossild1, stat(p50 mean)

gen dum_energy=0
replace dum_energy=1 if fossild1>=.7319233
gen   f_dum=fdepth*dum_energy

xtreg l_per_gdp  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 if dum_energy==0,fe
est store reg4
xtreg l_per_gdp  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 if dum_energy==1,fe
est store reg5
xtreg l_per_gdp  fdepth   f_dum   dum_energy gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 ,fe
est store reg6
esttab  reg4 reg5 reg6, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep ( fdepth   dum_energy  f_dum   _cons) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("Low" "High" "All" "Low" "High" "All") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  



//Technological innovation effect
replace f_dum=fdepth*dum_energy


xtreg tech  fdepth         gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 if dum_energy==0,fe
est store reg4
xtreg tech  fdepth       gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 if dum_energy==1,fe
est store reg5
xtreg tech  fdepth  f_dum  dum_energy  gdp_a cpi l_population l_fdi internet_use  env_regul stru_2,fe
est store reg6

esttab reg4 reg5 reg6, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth      f_dum dum_energy  _cons ) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("Low" "High" "All" "Low" "High" "All") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  

// Industrial structure upgrade effect
replace f_dum=fdepth*dum_energy

xtreg struct_s  fdepth         gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 if dum_energy==0,fe
est store reg4
xtreg struct_s  fdepth       gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 if dum_energy==1,fe
est store reg5
xtreg struct_s  fdepth  f_dum  dum_energy  gdp_a cpi l_population l_fdi internet_use  env_regul stru_2,fe
est store reg6

esttab reg4 reg5 reg6, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth      f_dum  dum_energy _cons) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("Low" "High" "All" "Low" "High" "All") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  





*****************************************robust test********************
reg SW fdepth   gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2   
est store reg1
xtgls SW  fdepth   gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2  i.year, panels(hetero)
est store reg2
xtreg SW  fdepth   gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2  ,fe
est store reg3
xtreg SW  fdepth   gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2 ,re
est store reg4
xtreg SW  fdepth  fdepth2 gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2  ,fe
est store reg5
xtivreg per_co2  (fdepth= fdepth_loan L.fdepth)  gdp_a cpi l_population l_fdi internet_use  env_regul tech stru_2  ,fe
xtoverid
dmexogxt
est store reg6
esttab reg1 reg2 reg3 reg4 reg5 reg6, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth  fdepth2   gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2 _cons) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("ols" "FGLS" "FE" "RE" "FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  /*table 3*/

hausman reg3 reg4

//mediting effect
xtreg SW  fdepth l_per_gdp   tech struct_s   gdp_a cpi l_population l_fdi internet_use  env_regul stru_2  l_trade,fe
est store reg1

xtreg l_per_gdp  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 l_trade,fe
est store reg3
xtreg tech  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 l_trade,fe
est store reg4
xtreg struct_s  fdepth      gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 l_trade,fe
est store reg5

esttab reg1  reg3 reg4 reg5 , cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth l_per_gdp  gdp_a cpi l_population l_fdi internet_use  env_regul struct_s tech stru_2 _cons) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("ols" "FGLS" "FE" "RE" "FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  /*table 3*/



